package org.springframework.cloud.netflix.feign.ribbon;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

@Configuration
public class CoreCanaryZuulAutoConfiguration {
    @Bean
    public CanaryProperties canaryProperties() {
        return new CanaryProperties();
    }

    @Bean
    public CoreCanaryFilter coreCanaryFilter(CanaryProperties canary) {
        CoreCanaryFilter.INSTANCE.setCanary(canary);
        return CoreCanaryFilter.INSTANCE;
    }

    @Bean
    public FilterRegistrationBean canaryFilterRegistrationBean(CoreCanaryFilter filter) {
        final FilterRegistrationBean bean = new FilterRegistrationBean(filter);
        bean.setOrder(Ordered.LOWEST_PRECEDENCE);
        return bean;
    }

    @Bean
    public static CanaryBeanPostProcessor canaryBeanPostProcessor() {
        return new CanaryBeanPostProcessor();
    }
}
